#include <iostream>
#include <map>
#include <sstream>

bool prime(int n)
{
    for (int i = 2; i < n; i++)
        if (n % i == 0) return 0;
    return 1;
}

int get_nearest_small(int n)
{
    while (!prime(--n));
    return n;
}

int get_nearest_big(int n) {
    while (!prime(n++));
    return n - 1;
}

std::map<std::string, uint8_t> result(
    {   
        {"one", 1},
        {"two", 2},
        {"three", 3},
        {"four", 4},
        {"five", 5},
        {"six", 6},
        {"seven", 7},
        {"eight", 8},
        {"nine", 9},
        {"zero", 0}
    }
);

int main() {
    std::string inp; 
    std::getline(std::cin, inp);
    std::stringstream ss(inp);
    std::string s1, s2, s3;

    ss >> s1 >> s2 >> s3;

    if (!result.count(s1) || !result.count(s2) || !result.count(s3)) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int to_find = result[s1] * 100 + result[s2] * 10 + result[s3];
    int bigger = get_nearest_big(to_find);
    int smaller = get_nearest_small(to_find);
    
    if (std::abs(to_find - bigger) < std::abs(to_find - smaller))
        std::cout << bigger << std::endl;
    else std::cout << smaller << std::endl;

    return 0;
}